import Config from "../../config/config";


export default class SqliteApi{
    _id=new Date();//默认有个_id
    _schemas(){
        let config={
            path:this.path(),
            name: this.constructor.name,
            primaryKey: this.primaryKey(),
            properties: this._properties(),
            schemaVersion:Config.DB_VERSION
        };
        return config;
    }
    _properties() {
        let ret = {};
        for (let key in this) {
            if (typeof this[key] === "string") {
                ret[key] = "text";
            } else if (typeof this[key] === "number") {
                if (Number.isInteger(this[key])) {
                    ret[key] = "int";
                } else {
                    ret[key] = "double";
                }
            } else if (this[key] instanceof Date) {
                ret[key] = "long";
            } else if (typeof this[key] === "boolean") {
                ret[key] = "boolean";
            } else if (this[key] instanceof Function) {
            } else {
                throw new Error("请查看" + key + "=" + this[key] + "的类型,以及是否给了初值");
            }
        }
        return ret;
    }
    path(){
        return "";
    }
    primaryKey() {
        return "_id";
    }

    migration(oldVersion, newVersion) {

    }

}
